<?
layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
	<div class="row">
		<div  class="col-md-12">
	            <div class="panel" style="overflow: auto;">
               	<div class="panel-body pan "style="width:auto; overflow: auto; height: 486px;" >
						<div class="form-body pal" style="float:left;width:100%; overflow: auto;"  >
	
							<div style="padding-bottom: 60px ;padding-top: -20px;" >
								
									<div class="input-group input-group-sm">
										<input id="nameZh" type="text" placeholder="主题款目词" class="form-control" value="" /><p id="nameZhTiShi"></p>
			                    		<span class="input-group-btn"><button type="button"  class="btn btn-blue btn-sm btn-default"  onclick="findThesauriWordList(1)">搜 &nbsp;索</button>
										</span>
									</div>
							</div>
	
							 <div class="panel " style="margin-top: -70px; margin-bottom: -15px; height: auto;">
                                <div class="panel-body">
                                    <table class="table table-hover-color">
                                        <thead>
                                            <tr>
                                            	<th width="5%"><input type="checkbox" class="checkall" /></th>
                                            	<th width="10%">序号</th>
                                                <th width="15%">主题款目词</th>
                                                <th>所属范畴</th>
                                                <th width="15%">可操作</th>
                                            </tr>
                                        </thead>
                                        <tbody id="findThesauriWord">
                                        </tbody>
                                    </table>
                                    <div  id="page2" style="text-align: center; margin-top: 20px;"></div>
                                    <div  id="dataNull2" class="panel-body"
												style="height: 90px; line-height: 50px;" align="center">
									</div>
                                </div>
                            </div>
                        </div>
							
						</div>	
				</div>
          </div>
</div>
<?} ?>
<script>
function getQueryString(name) { 
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r != null) return unescape(r[2]); return null; 
	} 
	var winName=getQueryString("winName");
	var category =getQueryString("category");
	var thesauriWordId=getQueryString("thesauriWordId");
	var referenceRelationLabel=getQueryString("source");
	var counts=getQueryString("count");
	var wordClasses=getQueryString("wordClasses");
	$(function() {
	
		findThesauriWordList(1);
	});
	var curr;
	function findThesauriWordList(curr) {
		$.getJSON(
						"./findThesauriWordList.do",
						{
							page : curr || 1,
							text : $("#nameZh").val(),
							category : category,
							thesauriWordId : thesauriWordId,
							wordClasses:wordClasses
						},
						function(res) {
							//此处仅仅是为了演示变化的内容
							var liebiao = "";
							if (res.listsize> 0) {
								$("#dataNull2").html("");
								$("#dataNull2").hide();
							} else {
								$("#dataNull2").show();
								$("#dataNull2").html("<span class='subtitle' style='font-size: 15px;'>无可操作项!</span>");
							}
							$("#findThesauriWord").html("");
							for ( var i = 0; i < res.listsize; i++) {
									liebiao += "<tr ><td>"
                                        			+"<input type='checkbox' name='check' value="+res.result[i].id+" />"
                                                +"</td><td>"
                                                	+(i+1)
                                                 +"</td><td>"
                                                	+res.result[i].wordName
                                                +"</td><td>"
                                                	+res.result[i].thesauriWordCategoryName
                                                +"</td><td>"
                                                + "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"addEditThesauriWord2('"
												+ res.result[i].id
												+ "')\">"
												+ "编辑"
												+ "</button>&nbsp;&nbsp;&nbsp;"
                                                + "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"delThesauriWord('"
												+ res.result[i].id
												+ "')\">"
												+ "删除"
												+ "</button>"
                                                +"</td></tr>";
							}
							$("#findThesauriWord").append(liebiao);
							laypage({
								cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
								pages : res.pageSize, //总页数
								skip : true, //是否开启跳页
								skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
								curr : curr || 1,
								last: res.pageSize,
								groups : 6,//连续显示分页数
								jump : function(obj, first) { //触发分页后的回调
									if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
										curr = obj.curr;
										findThesauriWordList(curr);
									};
								}
							});
						});
	};
	var cengjiguanxi=""; 
	if(winName==""){
		 cengjiguanxi=window.parent;
	}else{
		cengjiguanxi=window.parent.window[winName];
	}
	function queRen(){
		var check = document.getElementsByName("check");
			var len=check.length;
			var idAll="";
			var count=0;
			for(var i=0;i<len;i++){
				if(check[i].checked){
					count++;
					idAll+=check[i].value+",";
				}
			}
			idAll = idAll.substring(0,(idAll.length)-1);
			if(category==0){
				if(count==1){
					var index = parent.layer.getFrameIndex(window.name); 
		  		    cengjiguanxi.$("#thIds").val(idAll);
		  		   	cengjiguanxi.tuxinghua(wordClasses);
		  		    parent.layer.close(index);
				}else{
					alert("请勾选一个！！");
				}
			}
			if(category==2){
				if(count>0){
					$.getJSON("./addThesauriWordReference.do", {
						thesauriWordId : thesauriWordId,
						referenceWordId : idAll,
						referenceRelationLabel : referenceRelationLabel,
						wordClasses : wordClasses,
					}, function(res) {
						if (res.count < 1) {
							var index = parent.layer.getFrameIndex(window.name); 
							cengjiguanxi.tuxinghua(wordClasses);
							cengjiguanxi.findAllthesauriWordReferenceLieBiao(counts);
							cengjiguanxi.layer.msg('添加成功');
		  		   			parent.layer.close(index);
						}else{
							layer.msg(res.result[0].twordName+'：已有关联  ！添加失败');
						}
					});
				}else{
					alert("请勾选！！");
				}
			}
			if(category==4){
				if(count>0){
						$.getJSON("./addThesauriWordReference.do", {
							thesauriWordId : thesauriWordId,
							referenceWordId : idAll,
							referenceRelationLabel : referenceRelationLabel,
							wordClasses : wordClasses,
						}, function(res) {
							if (res.count < 1) {
								var index = parent.layer.getFrameIndex(window.name);
								cengjiguanxi.findEditThesauriWordReference();
								cengjiguanxi.layer.msg('添加成功');
			  		   			parent.layer.close(index);
							}else{
								layer.msg(res.result[0].twordName+'：已有关联  ！添加失败');
							}
						});
					}else{
						alert("请勾选！！");
					}
			}			
	}
	function delThesauriWord(id) {
			if (confirm("是否确认删除！！")) {
				$.ajax({
					type : "post",
					url : "./delThesauriWord.do",
					data : {
						"id" : id
					},
					dataType : "json",
					success : function(data) {
						if (data.count < 1) {
							findThesauriWordList(curr);
							layer.msg('删除成功');
						} else {
							layer.msg('删除失败！有关联项不可删除。请删除关联项后再删除。');
						}
					},
					error : function(data) {
						alert("请求失败");
					}
				});
			}
		}
		$("tr").live("click", function () {
		     if ($(this).hasClass("bgRed")) {
		         $(this).removeClass("bgRed").find(":checkbox").attr("checked", false);
		     } else {
		                $(this).addClass("bgRed").find(":checkbox").attr("checked", true);
		            }
		 });
	var id;
	function getThesauriWordId() {
			return id;
		}
	function getShanChu(){
		return 6;
	}
	function getsource() {
			return 1;
		}
	function getTwrId() {
			return 1;
		}
	function addEditThesauriWord2(lid) {
	
		id = lid;
		parent.layer.open({
					type : 2,
					area : [ '700px', '640px' ],
					scrollbar : false,
					shadeClose : true,
					fix : false, //不固定
					title : '主题款目词表',
					//maxmin : true,  
					skin : 'layui-layer-rim', //加上边框
					btn : ['保存','关闭 '],
					content : [ "word-thesauriWord-addEdit.html?winName="+window.name+"&addwordClasses="+wordClasses, 'no' ],
					yes : function(index, layer) {
						var iframeWin = parent.window[layer.find('iframe')[0]['name']];
						iframeWin.Page();
					},
					cancel : function(index) {
					}
				});
	}
	
</script>


